package dexter.util;

import java.util.concurrent.ConcurrentHashMap;

public class IdGenerator {

    private static final int NUM = 10;
    
	public static String generate() {
		return generate(NUM);
	}

    public static String generate(int n) {
		String id = "";
		
		int num=Integer.valueOf(n);
		int[] ids=new int[num];
		ConcurrentHashMap<String, Integer> h= new ConcurrentHashMap<String, Integer>();
		while(num>0){
			int val=0;
			for (int i=0; i<9; i++){
				int digit=(int) (Math.random()*10.0);
				val= (val*10)+digit;				
			}
			if (!h.containsKey(Integer.toString(val))){
				num--;
				ids[num]=val;
				id = Integer.toString(val);
				h.put(id, val);
			}			
		}
		
		return id;
	}
    
    public static void main(String[] args) {
    	
    	if (args.length>0) System.out.println(generate(Integer.parseInt(args[0])));
    	else System.out.println(generate());
    }

}
